﻿using System.Collections;
using System.Collections.ObjectModel;

namespace 双括号写法
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");

            EndPointCollection endPoints = new EndPointCollection 
            {
               new EndPoint{ Url="aaa",Port=198},new EndPoint{ Url="bbb",Port=18}
            
            };

            foreach (EndPoint endPoint in endPoints)
            {

                Console.WriteLine(endPoint.ToString());
            }

        }
    }


    class EndPoint
    {

        private int _port;
        private string _url;

        public int Port { get; set; }

        public string Url { get; set; }

        public EndPoint(string url, int port)
        {
            _port = port;
            _url = url;
        }

        public EndPoint() { }

        public override string? ToString()
        {
            return $"{Url}:{Port}";
        }
    }

    class EndPointCollection : Collection<EndPoint>, IEnumerable<EndPoint>, IEnumerable
    {
        public EndPointCollection() { }

        public EndPointCollection(IList<EndPoint> endpoints)
        : base(endpoints)
        {
        }

        public EndPointCollection EndPoints { get; init; } = new EndPointCollection();

    }
}
